﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Admin_Admin_Notice : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        InitMenu();
        OfficeDataClassesDataContext dc = new OfficeDataClassesDataContext();
        NewsListGridView.DataSource = from news in dc.News
                                      join news_category in dc.News_Categories
                                      on news.News_category equals news_category.Category_id
                                      where news_category.Category_name.Equals("重要通知")
                                      orderby news.Time descending
                                      select new
                                      {
                                          标识 = news.News_id,
                                          标题 = news.Title,
                                          日期 = news.Time.Value.Month + "-" + news.Time.Value.Day
                                      };
        NewsListGridView.DataBind();
        dc.Dispose();
    }


    protected void InitMenu()
    {

        OfficeDataClassesDataContext dc = new OfficeDataClassesDataContext();
        Menu1.Items.Clear();
        MenuItem MainPage = new MenuItem();
        MainPage.Enabled = true;
        MainPage.Selectable = true;
        MainPage.Selected = false;
        MainPage.Value = MainPage.ToolTip = MainPage.Text = "注销登陆";
        MainPage.NavigateUrl = "../Default.aspx";
        Menu1.Items.Add(MainPage);

        MenuItem navigation = new MenuItem();
        navigation.Value = navigation.ToolTip = navigation.Text = "页眉管理";
        navigation.NavigateUrl = "Admin_navigation.aspx";
        Menu1.Items.Add(navigation);

        MenuItem news = new MenuItem();
        news.Value = news.ToolTip = news.Text = "重要通知";
        Menu1.Items.Add(news);

        MenuItem catergory1 = new MenuItem();//定义子菜单
        catergory1.Text = "类别管理";
        catergory1.NavigateUrl = "Admin_DocumentCategory.aspx";
        Menu1.Items[2].ChildItems.Add(catergory1);//添加子菜单

        MenuItem aa1 = new MenuItem();
        aa1.Text = "重要通知管理";
        aa1.NavigateUrl = "Admin_Notice.aspx";
        Menu1.Items[2].ChildItems.Add(aa1);


        MenuItem document = new MenuItem();
        document.Value = document.ToolTip = document.Text = "校发文件";
        Menu1.Items.Add(document);

        MenuItem catergory2 = new MenuItem();//定义子菜单
        catergory2.Text = "类别管理";
        catergory2.NavigateUrl = "Admin_DocumentCategory.aspx";
        Menu1.Items[3].ChildItems.Add(catergory2);//添加子菜单

        MenuItem aa2 = new MenuItem();
        aa2.Text = "校发文件管理";
        aa2.NavigateUrl = "Admin_Document.aspx";
        Menu1.Items[3].ChildItems.Add(aa2);





        int a = 0;

        var Menus = from menu in dc.Menus
                    select new
                    {
                        MenuItem_id = menu.MenuItem_id,
                        MenuItem_Name = menu.MenuItem_Name
                    };

        foreach (var menu in Menus)
        {
            MenuItem menuitem = new MenuItem();
            menuitem.Enabled = true;
            menuitem.Selectable = true;
            menuitem.Selected = false;
            menuitem.ToolTip = menuitem.Text = menu.MenuItem_Name.Trim();
            menuitem.Value = menu.MenuItem_id.ToString();
            Menu1.Items.Add(menuitem);
            a++;
            MenuItem catergory = new MenuItem();//定义子菜单
            catergory.Text = "类别管理";
            catergory.NavigateUrl = "Admin_DocumentCategory.aspx";
            Menu1.Items[a + 3].ChildItems.Add(catergory);//添加子菜单

            MenuItem aa = new MenuItem();

            aa.Text = menu.MenuItem_Name.ToString();


            aa.Text = aa.Text.Trim() + "管理";
            Menu1.Items[a + 3].ChildItems.Add(aa);

        }
        Menu1.Items[4].ChildItems[0].NavigateUrl = "";
        Menu1.Items[4].ChildItems[1].NavigateUrl = "";
        Menu1.Items[5].ChildItems[1].NavigateUrl = "Admin_Orgnization.aspx";
        Menu1.Items[6].ChildItems[1].NavigateUrl = "Admin_Rule.aspx";
        Menu1.Items[7].ChildItems[1].NavigateUrl = "Admin_Meeting.aspx";
        Menu1.Items[8].ChildItems[1].NavigateUrl = "Admin_CollegeCondition.aspx";
        Menu1.Items[9].ChildItems[1].NavigateUrl = "Admin_Law.aspx";
        Menu1.Items[10].ChildItems[1].NavigateUrl = "Admin_Download.aspx";







        MenuItem link = new MenuItem();
        link.Value = link.ToolTip = link.Text = "链接管理";
        link.NavigateUrl = "Admin_Link.aspx";
        Menu1.Items.Add(link);

        MenuItem password = new MenuItem();
        password.Value = password.ToolTip = password.Text = "密码管理";
        password.NavigateUrl = "Admin_Password.aspx";
        Menu1.Items.Add(password);


        dc.Dispose();
    }
    protected void Logoff_Click(object sender, EventArgs e)
    {
        Session.Remove("admin");
        Response.Redirect("../Default.aspx");
    }
    protected void NoticeManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Notice.aspx");
    }
    protected void DocumentCategoryManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_DocumentCategory.aspx");
    }
    protected void DocumentManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Document.aspx");
    }
    protected void DownloadManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Download.aspx");
    }
    protected void PasswordManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Password.aspx");
    }
    protected void CollegeConditionManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_CollegeCondition.aspx");
    }
    protected void LawManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Law.aspx");
    }
    protected void MeetingManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Meeting.aspx");
    }
    protected void OrgnizationManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Orgnization.aspx");
    }
    protected void RuleManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Rule.aspx");
    }
    protected void LinkManagement_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin_Link.aspx");
    }
    protected void New_Button_Click(object sender, EventArgs e)
    {
        Session.Add("OperationType", "New");
        Session.Add("NewsType", "Notice");
        Response.Redirect("NewsEdit.aspx");
    }
    protected void NewsListGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {
            SQL.SQLHelper.Delete(Convert.ToInt32(((Label)NewsListGridView.Rows[e.RowIndex].FindControl("News_id")).Text));
        }
        catch (Exception ex)
        {
        }
        OfficeDataClassesDataContext dc = new OfficeDataClassesDataContext();
        NewsListGridView.DataSource = from news in dc.News
                                      join news_category in dc.News_Categories
                                      on news.News_category equals news_category.Category_id
                                      where news_category.Category_name.Equals("重要通知")
                                      orderby news.Time descending
                                      select new
                                      {
                                          标识 = news.News_id,
                                          标题 = news.Title,
                                          日期 = news.Time.Value.Month + "-" + news.Time.Value.Day
                                      };
        NewsListGridView.DataBind();
        dc.Dispose();
        
    }
    protected void NewsListGridView_RowEditing(object sender, GridViewEditEventArgs e)
    {
        Session.Add("OperationType", "Edit");
        Session.Add("News_id", ((Label)NewsListGridView.Rows[e.NewEditIndex].FindControl("News_id")).Text);
        Session.Add("NewsType", "Notice");
        Response.Redirect("NewsEdit.aspx");
    }
    protected void NewsListGridView_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void NewsListGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        NewsListGridView.PageIndex = e.NewPageIndex;
        DataBind(); //重新绑定GridView数据的函数
    }

}
